﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;

namespace GDoc.Domain
{
    public enum RoleEnum
    {
        Owner = 0,
        Administrator = 1,
        Member = 2
    }

    public class Role
    {
        [NotMapped]
        public RoleEnum Enum { get; set; }

        public int Value
        {
            get { return (int)Enum; }
            set { Enum = (RoleEnum)value; }
        }

        /// <summary>
        /// This operator make transparent the conversion of the enum and the wrapper.
        /// </summary>
        /// <param name="w">The wrapper to be converted</param>
        /// <returns>The enum value</returns>
        public static implicit operator RoleEnum(Role w)
        {
            if (w == null) return default(RoleEnum);
            return w.Enum;
        }

        /// <summary>
        /// This operator make transparent the conversion of the enum and the wrapper.
        /// </summary>
        /// <param name="c">The enum to be converted</param>
        /// <returns>The wrapper value</returns>
        public static implicit operator Role(RoleEnum c)
        {
            return new Role { Enum = c };
        }

        #region Object Overrides

        public override bool Equals(object obj)
        {
            if (obj is Role)
                return this.Enum.Equals((obj as Role).Enum);
            return base.Equals(obj);
        }

        public override int GetHashCode()
        {
            return this.Enum.GetHashCode();
        }

        #endregion Object Overrides
    }
}
